package com.example.workmanager.work;

import android.app.DownloadManager;
import android.content.Context;
import android.os.SystemClock;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

public class MyWork extends Worker {
    public MyWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
    }

    @NonNull
    @Override
    public Result doWork() {
        //接收从主页面传递的参数
        String data = getInputData().getString("input_data");
        Log.d("guaimiao", data);
        //SystemClock.sleep(2000);
        Log.d("guaimiao", "MyWork doWork");

        //任务执行完之后返回数据
        //将data对象放在success()中即可返回
        //在主页面的状态监听方法中获取返回的数据
        Data outputData = new Data.Builder()
                .putString("output_Data" , "执行完毕")
                .build();
        //返回success()表示任务成功
        //返回retry表示重新请求任务
        return Result.success(outputData);
    }
}
